<template>
	<view class="info">
		<view class="publisher">
			{{ formatName(item.user.nickname) || '平台发布人' }}
		</view>
		<view class="time">
			{{ item.createtime_text }}
		</view>
		<view class="comment">
			<uv-icon name="chat"></uv-icon>
			<text>{{ formatNumber(item.comment_num) }}</text>
		</view>
		<view class="like">
			<uv-icon name="thumb-up"></uv-icon>
			<text>{{ formatNumber(likeCount) }}</text>
		</view>
		<view class="views">
			<uv-icon name="eye"></uv-icon>
			<text>{{ formatNumber(viewCount) }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'articleInfoBar',

		data() {
			return {

			};
		},
		props: {
			item:{
				type:Object,
				default:{}
			},
			publisher: {
				type: String,
				required: true,
				default: '平台发布人'
			},
			time: {
				type: String,
				required: true,
				default: '2020-01-01 12:00'
			},
			commentCount: {
				type: String,
				required: true,
				default: '0'
			},
			likeCount: {
				type: String,
				required: true,
				default: '0'
			},
			viewCount: {
				type: String,
				required: true,
				default: '0'
			}
		},
		methods: {
			formatNumber(value) {
				console.log(value,'iiiiiiiiiiiiii');
				if (value >= 10000) {
					return (value / 10000).toFixed(1) + 'w'; // 将万转换为w
				} else if (value >= 1000) {
					return (value / 1000).toFixed(1) + 'k'; // 将千转换为k
				}
				if(!value){
					return 0;
				}
				return value;
			},
			formatName(value) {
				if (value == 'admin') {
					return '平台发布人';
				} else {
					return value;
				}
			},
			
		}

	}
</script>

<style lang="scss" scoped>
	.info {
		padding: 0 20rpx;
		font-size: 24rpx;
		color: #999999;
		display: flex;
		align-items: center;
		gap: 20rpx;
		white-space: nowrap;

		>view {
			display: flex;
			align-items: center;
			gap: 5rpx;

			>text {
				font-size: 24rpx;
				color: #999999;
			}
		}

		.comment {
			margin-left: auto;
		}
	}
</style>